package controller;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * A threaded work description that waits for input from the GUI and sends these
 * messages to the GCom model via the {@link controller.Controller}. Giving this
 * responsibility to a separate thread increases the responsiveness of the
 * application.
 * 
 */
public class InputQueueHandler implements Runnable {

    private final LinkedBlockingQueue<String[]> inputQueue;
    private final Controller control;

    public InputQueueHandler(final LinkedBlockingQueue<String[]> inputQueue,
            final Controller control) {
        this.inputQueue = inputQueue;
        this.control = control;

    }

    @Override
    public void run() {
        while (true) {
            try {
                control.submitInput(inputQueue.take());
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
